package com.hulei.studyproject.nacos.listener;

import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class NacosJsonDefaultListener<T> extends NacosAbstractListener<T> {
    @Autowired
    private NacosConfigProperties nacosConfigProperties;
    @Override
    protected String getGroupId() {
        return nacosConfigProperties.getGroup();
    }

    @Override
    protected String getNameSpace() {
        return nacosConfigProperties.getNamespace();
    }

    @Override
    protected String getServerAddr() {
        return nacosConfigProperties.getServerAddr();
    }

    @Override
    protected void compile(String dataStr) {
        data = JSON.parseObject(dataStr, this.JsonToObjectClass());
    }
    protected abstract Class<? extends T> JsonToObjectClass();
}
